package dynamic_programming;
//https://leetcode.cn/leetbook/read/illustration-of-algorithm/58nn7r/
public class LCR_188买卖芯片的最佳时机 {
    class Solution {
        public int bestTiming(int[] prices) {
            if(prices.length == 0) return 0;
            int cost = Integer.MAX_VALUE,profit = 0;
            for(int i : prices){
                cost = Math.min(cost,i);
                profit = Math.max(profit,i-cost);
            }
            return profit;
        }
    }
    //暴力
    class Solution2 {
        public int bestTiming(int[] prices) {
            if(prices.length == 0) return 0;
            int max = 0;
            int length = prices.length;
            for(int i = 0; i < length; i++){
                for(int j = i+1; j < length; j++){
                    max = Math.max(max,prices[j]-prices[i]);
                }
            }
            return max;
        }
    }
}